package com.example.server.controller.base;

import cn.hutool.json.JSONObject;
import com.example.server.common.config.annotation.MustLogin;
import com.example.server.common.constant.Result;
import com.example.server.service.base.ImageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author china.fuyao@outlook.com
 * @date 2020-04-21 15:20
 */
@Api(tags = "文件上传相关接口")
@RestController
@RequestMapping("/file/upload")
public class FileUploadController {
    @Resource
    ImageService imageService;

    @MustLogin(isAdmin = true)
    @ApiOperation(value = "获取图片上传签名", notes = "获取图片上传签名")
    @GetMapping("/policy")
    public Result getUploadImgPolicy() {
        return imageService.getUploadImgPolicy();
    }

    @MustLogin
    @ApiOperation(value = "服务器视频上传", notes = "服务器视频上传")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "图片文件", name = "file", required = true)
    })
    @PostMapping("/server/video")
    public Result uploadVideoByServer(MultipartFile file) {
        return new Result(imageService.uploadVideoByServer(file));
    }

    @MustLogin
    @ApiOperation(value = "服务器图片上传", notes = "服务器图片上传")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "图片文件", name = "file", required = true)
    })
    @PostMapping("/server/img")
    public Result uploadImgByServer(MultipartFile file) {
        return new Result(imageService.uploadImgByServer(file));
    }

    @MustLogin(isAdmin = true)
    @ApiOperation(value = "layedit图片上传", notes = "layedit图片上传")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "图片文件", name = "file", required = true)
    })
    @PostMapping("/layedit")
    public JSONObject uploadImgByLay(MultipartFile file) {
        return imageService.uploadImgByLay(file);
    }

}
